package com.fckbug.action.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.fckbug.service.UserService;
import com.fckbug.util.SpringContextHolder;
import com.fckbug.vos.Acc;
import com.mysql.jdbc.StringUtils;

/**
 * 查看用户的信息
 * @author think
 *
 */
public class ProfileAction extends Action {
	UserService userService = (UserService)SpringContextHolder.getBean("userService");
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String forward = request.getParameter("f");
		if(StringUtils.isNullOrEmpty(forward)) {
			forward = "read";
		}
		if(StringUtils.isNullOrEmpty(id)) {
			response.sendRedirect("/error/404.jsp");
			return null;
		}
		Acc acc = userService.getUserByUserId(Integer.parseInt(id));
		if(acc.getId()==null) {
			response.sendRedirect("/error/404.jsp");
			return null;
		}
		request.setAttribute("acc", acc);
		return mapping.findForward(forward);
	}
}
